<template>
    <div>
        <Form :label-width="100" inline>
            <Form-item label="名称">
                <Input v-model="queryParam.bcck0001" placeholder="校验名称" style="width: 300px"/>
            </Form-item>
            <Form-item label="保障类型">
                <dictSelect :sel_val='queryParam.bcck0005' dictCode="check_bus_type"
                            :bindData.sync="queryParam.bcck0005" style="width: 200px"/>
            </Form-item>
            <Form-item label="数据类型">
                <dictSelect :sel_val='queryParam.bcck0006' dictCode="check_table_type"
                            :bindData.sync="queryParam.bcck0006" style="width: 200px"/>
            </Form-item>

        </Form>
        <Row class="button_row">
            <span style="float:left">
                <Button type="primary" @click="handleAdd()">录入</Button>
            </span>
            <span style="float:right">
                <Button type="primary" @click="searchQuery">查询</Button>
                <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
            </span>
        </Row>
        <Modal v-model="visible" :title="title" width="600" style="position:relative;">
            <Form ref="formData" :model="formData" :label-width="150" :rules="rules">
                <FormItem label="名称" prop="bcck0001">
                    <Input v-model="formData.bcck0001" placeholder="" number style="width: 400px"/>
                </FormItem>
                <FormItem label="保障类型" prop="bcck0005">
                    <dictSelect :sel_val='formData.bcck0005' dictCode="check_bus_type"
                                :bindData.sync="formData.bcck0005" style="width: 400px"/>
                </FormItem>
                <FormItem label="数据类型" prop="bcck0006">
                    <dictSelect :sel_val='formData.bcck0006' dictCode="check_table_type"
                                :bindData.sync="formData.bcck0006" style="width: 400px"/>
                </FormItem>
                <FormItem label="校验SQL" prop="bcck0003">
                    <Input v-model="formData.bcck0003" placeholder="" style="width: 400px" type="textarea" :rows="5"/>
                </FormItem>
                <FormItem label="排序" prop="bcck0007">
                    <Input v-model="formData.bcck0007" placeholder="" number style="width: 400px"/>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button @click="visible = false">关闭</Button>
                <Button type="primary" @click="handleSubmit('formData')" v-if="showSubmit">确定</Button>
            </div>
        </Modal>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :radio-config="{highlight: true}"
                       :data="tableData">
                <!--                <vxe-table-column type="radio" width="60" align="center" fixed="left"/>-->
                <vxe-table-column field="bcck0001" title="名称" align="left" fixed="left" width="300px"/>
                <vxe-table-column field="bcck0005_name" title="保障类型" align="center" fixed="left" width="150px"/>
                <vxe-table-column field="bcck0006_name" title="数据类型" align="center" fixed="left" width="150px"/>
                <vxe-table-column field="bcck0003" title="校验SQL" align="left"/>
                <vxe-table-column title="操作" align="center" fixed="right" width="200px">
                    <template #default="{ row }">
                        <Button type="info" size="small" style="margin-right: 5px" @click="handleEdit(row)">编辑</Button>
                        <Button type="error" size="small" style="margin-right: 5px" @click="handleDel(row)">删除</Button>
                        <Button type="success" size="small" style="margin-right: 5px" @click="handleView(row)">详情
                        </Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import DateFormat from '@/plugins/format.js'

    export default {
        mixins: [CommonMixin],
        components: {
            dictSelect
        },
        data() {
            return {
                rules: {
                    bcck0001: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                    bcck0005: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                    bcck0006: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                    bcck0003: [
                        {required: true, message: '信息必填', trigger: 'blur'}
                    ],
                },
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss00015Service/getPageList",
                    edit: "/api/ac/subsistence/ss00015Service/updateData",
                    add: "/api/ac/subsistence/ss00015Service/insertData",
                    delete: "/api/ac/subsistence/ss00015Service/deleteData",
                },
                formData: {},
                queryParam: {},
                visible: false,
                showSubmit: true,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: ""
            }
        },
        methods: {
            handleAdd() {
                let that = this;
                that.title = "校验配置录入"
                let record = {};
                that.visible = true
                that.showSubmit = true
                that.formData = Object.assign({}, record)
            },
            handleEdit(row) {
                let that = this;
                that.title = "校验配置编辑"
                let record = row;
                if (record.id) {
                    that.visible = true
                    that.showSubmit = true
                    that.formData = Object.assign({}, record)
                } else {
                    that.visible = false
                }
            },
            handleView(row) {
                let that = this;
                that.title = "校验配置查看"
                let record = row;
                if (record.id) {
                    that.visible = true
                    that.showSubmit = false
                    that.formData = Object.assign({}, record)
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let that = this;
                        let dataParam = that.formData
                        let url = null;
                        if (dataParam.id == null) {
                            url = that.url.add
                        } else {
                            url = that.url.edit
                        }
                        postAction(url, dataParam).then((res) => {
                            if (res.data.errcode === 0) {
                                this.$Message.success(res.data.data.msg);
                                that.visible = false
                                this.loadData();
                            } else {
                                this.$Message.error(res.data.errmsg);
                            }
                        }).finally(() => {

                        })
                    } else {
                        this.$Notice.error({title: '必填信息未填写完成!', desc: '必填信息未填写完成!'})
                    }
                });
            },
            handleDel(row) {
                let that = this;
                let record = row;
                if (confirm('确定删除配置数据?')) {
                    postAction(that.url.delete, record).then((res) => {
                        if (res.data.errcode === 0) {
                            this.$Message.success(res.data.data.msg);
                            that.visible = false
                            this.loadData();
                        } else {
                            this.$Message.error(res.data.errmsg);
                        }
                    }).finally(() => {

                    })
                }
            },
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    .paging {
        float: right;
        margin-top: 10px;
    }

    /deep/ .ivu-upload-list {
        display: none;
    }
</style>
